from modulefinder import AddPackagePath

import pytest
from Buiness.LoginPage import LoginPage
from Buiness.MainPage import MainPage
from Buiness.Back_stagePage import Back_stagePage
from Buiness.Add_membersPage import Add_members
from common.log_tools import log
from common.yaml_tools import YamlTools
from Buiness.Member_listPage import Member_listPage


class TestOA:
#测试首页登陆
    # testdata = [("admin","123456","签退"),
    #             ("","123456","登录失败，请检查您的成员名或密码是否填写正确。"),
    #             ("admin","","登录失败，请检查您的成员名或密码是否填写正确。"),
    #             ("adminadfafsdafsa", "", "登录失败，请检查您的成员名或密码是否填写正确。")
    #             ]
    # testdata=[{"username":"admin","password":"123456","expect":"签退","type":"正向"},
    #           {"username":"","password":"123456","expect":"登录失败，请检查您的成员名或密码是否填写正确。","type":"反向"},
    #           {"username":"admin","password":"","expect":"登录失败，请检查您的成员名或密码是否填写正确。","type":"反向"}]
    testdata=YamlTools.read_yaml_file("test1.yaml")
    @pytest.mark.parametrize("testdata",testdata)
    @pytest.mark.run()
    # @pytest.mark.parametrize("username,password,expect",testdata)
    # @pytest.mark.run()
    # def test_login(self, get_driver, username, password, expect):
    #     loginpage = LoginPage(get_driver)
    #     loginpage.test_login(username=username, password=password, expect=expect)
    # def test_login(self,get_driver,testdata):
    #     try:
    #         lg=LoginPage(driver=get_driver)
    #         lg.test_login(username=testdata["username"],password=testdata["password"])
    #         if testdata["type"]=="正向":
    #             mg=Back_stagePage(driver=get_driver)
    #             assert mg.get_assert_text()==testdata["expect"],"登录失败"
    #         else:
    #             assert lg.get_assert_text()==testdata["expect"],"登录失败"
    #     except Exception as e:
    #         log.error(e)
    #         raise e

    def test_add_member(self,get_driver,testdata):
        try:
            add=Add_members(driver=get_driver)
            add.test_addmember(username=testdata["username"],realname=testdata["realname"],
                               password1=testdata["password1"],
                               password2=testdata["password2"],
                               num=testdata["num"],
                               email=testdata["email"])
            if testdata["type"]=="正向":
                add=Member_listPage(driver=get_driver)
                assert add.assert_text_jy==testdata["expect"],"保存失败"
            elif testdata["type"] =="反向":
                assert add.get_assert_namepass() == testdata["expect"], "保存失败"
            elif testdata["type"]=="反向":
                assert add.get_assert_lenmax()==testdata["expect"],"保存失败"
            else:
                assert add.get_assert_password()==testdata["expect"],"保存失败"
        except Exception as e:
            log.error(e)
            raise e

